﻿<template>
  <div class="container" style="width:99%;margin-top:-25px;">
    <!-- 查询条件 -->
    <div class="query-box">
      <el-form :model="queryBox" status-icon ref="queryBox">
        <el-row>
          <el-col :span="4">
            <div class="depart-box">
              <div class="slect-title">客户类型</div>
              <el-select clearable filterable v-model="queryBox.customerType">
                <el-option
                  v-for="item in student_type_options"
                  :key="item.key"
                  :label="item.value"
                  :value="item.key"
                ></el-option>
              </el-select>
            </div>
          </el-col>
          <el-col :span="4">
            <div class="depart-box">
              <div class="slect-title">客户来源</div>
              <el-select
                filterable
                clearable
                v-model="queryBox.customerSource"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in student_data_from_options"
                  :key="item.key"
                  :label="item.value"
                  :value="item.key"
                  >{{ item.value }}</el-option
                >
              </el-select>
            </div>
          </el-col>
          <el-col :span="4">
            <div class="depart-box">
              <div class="slect-title">客户进展</div>
              <el-form-item @change="student_progress_change">
                <el-select
                  clearable
                  filterable
                  v-model="queryBox.customerProgress"
                  placeholder="请选择"
                >
                  <el-option
                    v-for="item in student_progress_options"
                    :key="item.key"
                    :label="item.value"
                    :value="item.key"
                    >{{ item.value }}</el-option
                  >
                </el-select>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="4">
            <el-form-item label prop="phone ">
              <el-input v-model="queryBox.phone" placeholder="联系电话">
                <template slot="prepend">联系电话</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label prop="agentName ">
              <el-input v-model="queryBox.agentName" placeholder="意向客户">
                <template slot="prepend">意向客户</template>
              </el-input>
            </el-form-item>
          </el-col>
          <!-- <el-col :span="4">
            <el-form-item label prop="customerNumber">
              <el-input v-model="queryBox.customerNumber" placeholder="客户编号">
                <template slot="prepend">客户编号</template>
              </el-input>
            </el-form-item>
          </el-col>-->
          <!-- <el-col :span="4">
            <el-form-item label prop="contacts">
              <el-input v-model="queryBox.contacts" placeholder="学生名称">
                <template slot="prepend">联系人</template>
              </el-input>
            </el-form-item>
          </el-col>-->
        </el-row>
        <el-row>
          <el-col :span="4">
            <div class="depart-box">
              <el-form-item label prop="isTodayTracking">
                <div class="depart-box">
                  <div class="slect-title">今日应跟进</div>
                  <el-select
                    clearable
                    v-model="queryBox.sTodayTracking"
                    filterable
                  >
                    <el-option
                      v-for="item in isTodayTracking_options"
                      :key="item.lable"
                      :label="item.value"
                      :value="item.label"
                    ></el-option>
                  </el-select>
                </div>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="9">
            <el-row class="area">
              <el-col :span="6" style="margin-left:0">
                <span class="city-title">所在地区：</span>
              </el-col>
              <el-col :span="17" style="margin-left:-1px;width:75%">
                <el-form-item label prop="area">
                  <el-cascader
                    clearable
                    size="large"
                    :options="options"
                    v-model="selectedOptions"
                  ></el-cascader>
                </el-form-item>
              </el-col>
            </el-row>
          </el-col>
          <el-col :span="9">
            <div class="depart-box">
              <div class="slect-title">创建时间</div>
              <el-date-picker
                v-model="createDate"
                type="daterange"
                :start-placeholder="'开始时间'"
                :end-placeholder="'结束时间'"
                range-separator="至"
                :default-time="['00:00:00', '23:59:59']"
                value-format="yyyy-MM-dd HH:mm:ss"
                format="yyyy-MM-dd HH:mm:ss"
              ></el-date-picker>
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="4">
            <el-form-item label prop="name">
              <el-input v-model="queryBox.keyWord" placeholder="请输入内容">
                <template slot="prepend">关键字</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <div class="depart-box">
              <div class="slect-title">获取方式</div>
              <el-select
                clearable
                v-model="queryBox.allotType"
                filterable
                @change="student_parent_type_change"
              >
                <el-option
                  v-for="item in student_data_from_type_options"
                  :key="item.key"
                  :label="item.value"
                  :value="item.key"
                ></el-option>
              </el-select>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="depart-box">
              <div class="slect-title" style="width:32%">最新跟进时间</div>
              <el-date-picker
                v-model="trackingDate"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :default-time="['00:00:00', '23:59:59']"
                value-format="yyyy-MM-dd HH:mm:ss"
                format="yyyy-MM-dd HH:mm:ss"
              ></el-date-picker>
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <div class="depart-box">
              <div class="slect-title" style="width:32%">应跟进时间</div>
              <el-date-picker
                v-model="nextTrackingDate"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :default-time="['00:00:00', '23:59:59']"
                value-format="yyyy-MM-dd HH:mm:ss"
                format="yyyy-MM-dd HH:mm:ss"
              ></el-date-picker>
            </div>
          </el-col>
          <el-col :span="4">
            <div class="depart-box">
              <el-form-item label prop="isTodayTracking">
                <div class="depart-box">
                  <div class="slect-title">紧急回访客户</div>
                  <el-select v-model="queryBox.isRecoveredCustomer">
                    <el-option
                      v-for="item in isRecoveredCustomer_options"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    ></el-option>
                  </el-select>
                </div>
              </el-form-item>
            </div>
          </el-col>
        </el-row>
      </el-form>
      <div class="from-btns">
        <kt-button
          :label="$t('action.reset')"
          perms="true"
          type="primary"
          @click="reset('queryBox')"
        />
        <kt-button
          :label="$t('action.search')"
          perms="true"
          type="primary"
          @click="search"
        />
      </div>
    </div>
    <!-- 批量删除按钮 -->
    <div class="add-btns fl">
      <!-- <kt-button :label="$t('action.batchdistribution')" :disabled="this.selections.length===0" 
    perms="customer:student:batchdistribution" type="primary" @click="handlebatchdistribution"/>
    <kt-button :label="$t('action.batchdsubcenter')" :disabled="this.selections.length===0"  
      perms="customer:student:batchcenter" @click="handleCustomerOwnership" type="primary" />-->
      <kt-button
        label="移入客户公海"
        perms="mycustomer:xuecoo:delete"
        :size="size"
        type="danger"
        @click="handleBatchDelete"
        :disabled="this.selections.length === 0"
        style="float:left;"
      />
    </div>
    <div class="fr">
      <kt-button
        :label="$t('action.download-tmpl')"
        type="primary"
        perms="mycustomer:xuecoo:download"
        @click="downloadTmpl"
      ></kt-button>
      <kt-button
        :label="$t('action.batchimport')"
        type="primary"
        perms="mycustomer:xuecoo:batchimport"
        @click="customerManagerImport"
      ></kt-button>
      <kt-button
        :label="$t('action.add-user')"
        type="primary"
        perms="mycustomer:xuecoo:add"
        @click="handleNewADD"
      ></kt-button>
    </div>
    <!--表格内容栏-->
    <div class="btn">
      <Crm-table
        @selectionChange="selectionChange"
        class="table-width"
        Mycustomerxuecoo
        width="400"
        permsEdit="mycustomer:xuecoo:edit"
        permsSee="mycustomer:xuecoo:see"
        permsOutbound="mycustomer:xuecoo:outbound"
        permsFollow="mycustomer:xuecoo:follow"
        :data="pageResult"
        :columns="columns"
        :loading="loading"
        @findPage="findPage"
        @handleFollow="handleFollow"
        @handleEdit="handleEdit"
        @handleSee="handleSee"
        @handleoutbound="handleoutbound"
      ></Crm-table>
    </div>

    <!--导入-->
    <el-dialog
      :title="'批量导入'"
      width="30%"
      :visible.sync="uploadOem"
      :close-on-click-modal="false"
    >
      <el-form :model="form">
        <el-form-item>
          <el-upload
            ref="uploadExcel"
            :action="uploadUrl"
            :limit="limitNum"
            :auto-upload="false"
            accept=".xls"
            :before-upload="beforeUploadFile"
            :on-change="fileChange"
            :on-exceed="exceedFile"
            :on-success="handleSuccess"
            :on-error="handleError"
            :on-remove="handleRemove"
            :file-list="fileList"
          >
            <el-button size="small" plain>选择文件上传</el-button>
            <div slot="tip" class="el-upload__tip">
              只能上传xls(Excel97-2004)文件
            </div>
          </el-upload>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :size="size" @click.native="uploadOem = false">{{
          $t("action.cancel")
        }}</el-button>
        <el-button :size="size" type="primary" @click.native="uploadFile">{{
          $t("立即上传")
        }}</el-button>
      </div>
    </el-dialog>
    <!-- 跟进 -->
    <el-dialog
      :title="saveData.agentName"
      width="70%"
      :visible.sync="addFollow"
      @close="closeAddFollow"
      class="chinaeduAddfollow"
    >
      <div class="second-contain-box ma">
        <el-row>
          <el-col :span="12">
            <el-col :span="5">
              <span style="font-size:15px;">电话：</span>
            </el-col>
            <el-col :span="7">
              <span style="margin-left:20px">{{
                addTrackingInfo.investmentInfo.contactPhone
              }}</span>
            </el-col>
            <el-col :span="7">
              <span style="margin-left:20px">{{
                addTrackingInfo.investmentInfo.phoneAdress
              }}</span>
            </el-col>
          </el-col>
          <el-col :span="12">
            <el-col :span="6">地区：</el-col>
            <el-col :span="18">
              <!-- {{ saveData.diqu }} -->
              <el-cascader
                clearable
                size="large"
                :options="options"
                v-model="saveDataDiqu"
                @change="diquChange()"
              ></el-cascader>
            </el-col>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-row>
              <el-col :span="6">
                <i>备用电话：</i>
              </el-col>
              <el-col :span="16" style="margin-bottom:0;">
                <el-input
                  :disabled="isSpareChange"
                  v-model="addTrackingInfo.investmentInfo.phone1"
                  type="number"
                  @change="spareChange"
                ></el-input>
              </el-col>
            </el-row>
          </el-col>
          <el-col :span="12">
            <el-row>
              <el-col :span="6">
                <i>备用电话2：</i>
              </el-col>
              <el-col :span="18" style="margin-bottom:0;">
                <el-input
                  :disabled="isSpareChange2"
                  v-model="addTrackingInfo.investmentInfo.phone2"
                  type="number"
                  @change="spareChange2"
                ></el-input>
              </el-col>
            </el-row>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-col :span="6">
              <i>跟进次数：</i>
            </el-col>
            <el-col :span="16">
              <span
                style="text-align:left;margin-top:10px !important;display:inline-block"
                >{{ saveData.trackingTimes }}</span
              >
            </el-col>
          </el-col>
          <el-col :span="12" style="margin:5px 0 !important">
            <el-col :span="6">
              <i style="margin-top:0">跟进时间：</i>
            </el-col>
            <el-col :span="18">
              <span
                style="text-align:left;margin-top:10px!important;display:inline-block"
                >{{ saveData.trackingDate }}</span
              >
            </el-col>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-col :span="6">
              <i>城市类型：</i>
            </el-col>
            <el-col :span="18">
              <span style="margin-top:16px;display: inline-block;">{{
                saveData.cityType
              }}</span>
            </el-col>
          </el-col>
          <el-col :span="12">
            <el-col :span="6">
              <i>客户来源：</i>
            </el-col>
            <el-col :span="18">
              <span style="margin-top:16px;display: inline-block;">{{
                saveData.customerSource
              }}</span>
            </el-col>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-col :span="6">
              <i>关键字：</i>
            </el-col>
            <el-col :span="16">
              <el-input
                placeholder="请输入内容"
                v-model="addTrackingInfo.investmentInfo.keyWord"
              ></el-input>
            </el-col>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-col :span="6">
              <i>联系人：</i>
            </el-col>
            <el-col :span="16">
              <el-input
                placeholder="请输入内容"
                v-model="saveData.trackingContact"
              ></el-input>
            </el-col>
          </el-col>
          <el-col :span="12">
            <el-col :span="6">
              <i>沟通形式：</i>
            </el-col>
            <el-col :span="18">
              <el-select
                style="width:100%"
                v-model="saveData.communicationType"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in student_communication_type"
                  :key="item.value"
                  :label="item.value"
                  :value="item.key"
                ></el-option>
              </el-select>
            </el-col>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-col :span="6">
              <i>客户类型：</i>
            </el-col>
            <el-col :span="16">
              <el-select
                style="width:100%"
                :disabled="typeDisabled"
                v-model="saveData.customerType"
                placeholder="请选择"
                @change="typeChange"
              >
                <el-option
                  v-for="item in student_type_options"
                  :key="item.value"
                  :label="item.value"
                  :value="item.key"
                ></el-option>
              </el-select>
            </el-col>
          </el-col>
          <el-col :span="12">
            <el-col :span="6">
              <i>客户进展：</i>
            </el-col>
            <el-col :span="18">
              <el-select
                style="width:100%"
                :disabled="selectDisabled"
                v-model="saveData.customerProgress"
                placeholder="请选择"
                @change="progressChange"
              >
                <el-option
                  v-for="item in student_progress_options"
                  :key="item.key"
                  :label="item.value"
                  :value="item.key"
                ></el-option>
              </el-select>
            </el-col>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-col :span="3">
              <i>沟通内容：</i>
            </el-col>
            <el-col :span="21">
              <el-input
                style="width:100%"
                type="textarea"
                :rows="2"
                placeholder="请输入内容"
                v-model="saveData.communicationContent"
              ></el-input>
            </el-col>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-col :span="3">
              <i>客户备注：</i>
            </el-col>
            <el-col :span="21">
              <el-input
                style="width:100%"
                type="textarea"
                :rows="2"
                placeholder="请输入内容"
                v-model="addTrackingInfo.investmentInfo.customerRemark"
              ></el-input>
            </el-col>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-col :span="6">
              <i style="margin-top:5px">跟进人：</i>
            </el-col>
            <el-col :span="18" style="margin-top:10px;">{{
              trackingPeople
            }}</el-col>
          </el-col>
          <el-col :span="12">
            <el-col :span="6">
              <i>下次跟进日期：</i>
            </el-col>
            <el-col :span="18">
              <el-date-picker
                style="width:100%"
                v-model="saveData.nextTrackingDate"
                type="datetime"
                placeholder="选择日期时间"
                :default-time="mytime"
                value-format="yyyy-MM-dd HH:mm:ss"
                format="yyyy-MM-dd HH:mm:ss"
                :picker-options="pickerOptions"
              ></el-date-picker>
            </el-col>
          </el-col>
        </el-row>
      </div>
      <kt-button
        class="stu-btn"
        :label="$t('action.save')"
        type="primary"
        perms="true"
        size="medium"
        @click="handleSave()"
      />
      <p class="tracking-tit">跟进情况</p>
      <Crm-table
        :showBatchDelete="showBatchDelete"
        class="tracking-table"
        :data="stuqueryTrackingData"
        :columns="columns2"
        @findPage2="findPage2"
        :loading="loading"
      ></Crm-table>
    </el-dialog>
  </div>
</template>
<script>
import PopupTreeInput from "@/components/PopupTreeInput";
import KtButton from "@/views/Core/KtButton";
import CrmTable from "@/views/Core/CrmTable";
import CrmSwitch from "@/views/Core/CrmSwitch";
import { CodeToText } from "element-china-area-data";
import { isMobile } from "@/utils/validate";
import { regionDataPlus } from "element-china-area-data";
import { baseUrl } from "@/utils/global";
import Cookies from "js-cookie";
import axios from "axios";
export default {
  name: "Xuecoo",
  components: {
    PopupTreeInput,
    CrmTable,
    KtButton,
    CrmSwitch
  },
  data() {
    return {
      aa: true,
      selectDisabled: false, //跟进弹窗客户进展状态
      typeDisabled: false,
      showBatchDelete: false,
      checkedPeson: 0,
      size: "small",
      // filters: {
      //   name: ""
      // },
      // 查询条件
      student_data_from_options: [
        {
          label: " ",
          key: " "
        }
      ],
      student_type_options: [],
      saveDataDiqu: [],
      addTrackingInfo: {
        investmentInfo: {
          phone1: "",
          phone2: ""
        },
        trackingInfo: {}
      }, //客户基本信息
      student_progress_options: [
        {
          label: " ",
          key: " "
        }
      ],
      student_data_from_type_options: [
        {
          label: " ",
          key: " "
        }
      ],
      // 客户跟进数据
      stuqueryTrackingData: {
        content: []
      },
      queryBox: {
        belongType: "1",
        customerSource: "",
        customerProgress: "",
        allotType: "",
        lockStatus: "",
        assigner: "",
        sTodayTracking: "",
        isRecoveredCustomer: "0",
         customerType:'',
        customerSource:'',
        customerProgress:'',
        phone:'',
        agentName:'',
        keyWord:'',
      },
      trackingDate: "",
      createDate: "",
      width: 200,
      columns: [
        { type: "index", label: "序号", minWidth: 50 },
        { prop: "agentName", label: "意向客户", minWidth: 100 },
        { prop: "contactPhone", label: "联系电话", minWidth: 100 },
        { prop: "keyWord", label: "关键字", minWidth: 140 },
        { prop: "diqu", label: "地区", minWidth: 190 },
        { prop: "customerSource", label: "客户来源", minWidth: 100 },
        { prop: "customerProgress", label: "客户进展", minWidth: 70 },
        { prop: "allotType", label: "获取方式", minWidth: 70 },
        // { prop: "contacts", label: "联系人", minWidth:100 },
        {
          prop: "createDate",
          sortable: "true",
          label: "创建时间",
          minWidth: 140
        },
        {
          prop: "trackingDate",
          sortable: "true",
          label: "最新跟进时间",
          minWidth: 140
        },
        {
          prop: "nextTrackingDate",
          sortable: "true",
          label: "应跟进时间",
          minWidth: 140
        }

        // { prop: "customerNumber", label: "客户编号", minWidth: 150 },
      ],
      columns2: [
        { type: "index", label: "序号", minWidth: 10 },
        { prop: "trackingDate", label: "跟进时间", minWidth: 100 },
        { prop: "trackingContact", label: "联系人", minWidth: 50 },
        { prop: "communicationType", label: "沟通形式", minWidth: 50 },
        { prop: "customerType2", label: "客户类型", minWidth: 80 },
        { prop: "customerProgress", label: "客户进展", minWidth: 50 },
        { prop: "communicationContent", label: "沟通内容", minWidth: 120 },
        { prop: "nextTrackingDate", label: "下次跟进时间", minWidth: 100 }
      ],
      pageResult: {
        content: []
      },
      student_type_options: [],
      operation: true, // true:新增, false:编辑
      batchdistribution: false, //显示批量分配弹窗
      customerownership: false, //显示客户归属弹窗
      addFollow: false, //显示跟进窗口
      selectionsLength: "",
      deptTreeProps: {
        label: "name",
        children: "children"
      },
      roles: [],
      selections: [], //选中列表集合
      ids: [], //分配ID集合
      ids2: [],
      deptData: [], //部门树
      deptTree: {
        label: "deptName",
        children: "children"
      },
      deptinputValue: "",
      // 划分方式
      deptmodeoptions: [
        {
          label: "分配至部门",
          value: "11"
        },
        {
          label: "分配至个人",
          value: "9"
        }
      ],
      isTodayTracking_options: [
        {
          value: "是",
          label: "1"
        }
      ],
      isRecoveredCustomer_options: [
        {
          value: "1",
          label: "是"
        },
        {
          value: "0",
          label: "否"
        }
      ],
      deptmodeoptionsValue: "",
      submitID: "",
      deptId: "",
      userID: "", //人员ID
      deptuseroption: [], //部门用户
      deptuseroptionValue: "",
      branchcenter: [], //分中心下拉
      branchcenterValue: "",
      branchcenterValueID: "",
      branchcenterCodeValue: "", //分中心编码
      addstuformData: [],
      student_type_options: [],
      tQtoken: "",
      // 地区
      options: regionDataPlus,
      selectedOptions: [],
      // 呼叫信息
      demo: browserfly.noConflict(),
      callDate: "", //呼叫时间
      timeLength: "", //通话时长
      tqCode: "", //通话的TQ号
      isGetThrough: "", //是否接通
      contractPeople: "", //联系人
      seatCode: "", //坐席号
      studentId: "", //呼叫的学生ID
      callState: "", //挂断方式
      uploadOem: false, //文件上传
      limitNum: 1, //上传最大个数
      form: {
        file: ""
      },
      fileList: [],
      uploadUrl: baseUrl + "/file/upload", //文件上传地址
      downloadTmplUrl: baseUrl + "/template/studentImportTemplate.xlsx", //模板下载地址
      stuTableData: {
        studentInfo: {
          trackingNum: 1
        }
      },
      saveData: {
        customerType: "",
        trackingDate: "",
        customerProgress: "",
        contractContent: "",
        nextContractDate: "",
        contactPeople: "",
        customerId: "",
        trackingTimes: 0,
        communicationType: "",
        phoneAdress: "",
        nextTrackingDate: "",
        trackingContact:''
      },
      trackingPeople: Cookies.get("realName"),
      student_communication_type: [],
      // 分中心名称
      restaurants: [],
      branchCenterName: "",
      userName: "",
      agentName: "",
      mytime: "",
      loading: false, // 加载标识
      // 限制跟进时间
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() < Date.now() - 8.64e7; //如果没有后面的-8.64e7就是不可以选择今天的
        }
      },
      pageRequest2: {
        pageNum: 1,
        pageSize: 10
      },
      nextTrackingDate: "",
      isSpareChange: true,
      isSpareChange2: true
    };
  },
  beforeCreate: function() {
    // 获取初始化的TQtoken

    // this.tQtoken=Cookies.get('tqToken')
    const admin_uin = Cookies.get("admin_uin");
    const uin = Cookies.get("uin");
    const strid = "";
    const appid = Cookies.get("appid");
    const appkey = Cookies.get("appkey");
    const ct = Math.round(new Date().getTime() / 1000).toString();
    const sign2 = hex_md5(appid + "*(**)*" + appkey).toUpperCase();
    const ss =
      admin_uin +
      "&" +
      uin +
      "&" +
      strid +
      "&" +
      appid +
      "&" +
      sign2 +
      "&" +
      ct;
    const sign1 = hex_md5(ss).toUpperCase();
    const sign = sign2.toUpperCase();
    axios
      .get("/api/vip/open/auth/token", {
        params: {
          admin_uin: admin_uin,
          uin: uin,
          strid: strid,
          appid: appid,
          ct: ct,
          sign: sign1
        }
      })
      .then(res => {
        // console.log("adadasda" + res);
        this.tQtoken_init = res.data.access_token;
        console.log(res);
        // localStorage.setItem("TQtoken", res.data.access_token);
        this.TQtoken_init = res.data.access_token;
        Cookies.set("TQtoken_init", res.data.access_token);
      });
  },
  methods: {
    // 搜索
    search() {
      this.loading = true;
      this.queryBox.province = this.selectedOptions[0];
      this.queryBox.city = this.selectedOptions[1];
      this.queryBox.area = this.selectedOptions[2];
      this.queryBox.createStartDate = this.createDate[0];
      this.queryBox.createStopDate = this.createDate[1];
      this.queryBox.trackingStartDate = this.trackingDate[0];
      this.queryBox.trackingStopDate = this.trackingDate[1];
      this.queryBox.nextTrackingStartDate = this.nextTrackingDate[0];
      this.queryBox.nextTrackingStopDate = this.nextTrackingDate[1];
      this.pageRequest.pageNum = 1;
      this.findPage(null);
    },
    // 获取分页数据
    findPage: function(data) {
      if (
        this.queryBox.isRecoveredCustomer == 1 &&
        (this.queryBox.customerType == "" || this.queryBox.customerType == null)
      ) {
        this.loading = false;
        this.$message({
          message: "请选择客户类型",
          type: "error"
        });
        return;
      }
      if (data !== null) {
        this.loading = true;
        this.pageRequest = data.pageRequest;
      }

      this.queryBox.pageSize = this.pageRequest.pageSize;
      this.queryBox.pageNum = this.pageRequest.pageNum;
      if (this.queryBox.sTodayTracking == "" && this.nextTrackingDate == "") {
        this.pageRequest = Object.assign({}, this.pageRequest, this.queryBox, {
          belongType: 1,
          sortField: "create_date",
          sortType: "desc",
          isContainF: "1" //F类型的查询
        });
      } else {
        this.pageRequest = Object.assign({}, this.pageRequest, this.queryBox, {
          belongType: 1,
          sortField: "next_tracking_date",
          sortType: "asc",
          isContainF: "1" //F类型的查询
        });
      }

      this.$api.agent
        .investmentQueryXuecoo(this.pageRequest)
        .then(res => {
          if (res.result == 2) {
            this.$message({
              message: res.msg,
              type: "error"
            });
            this.loading = false;
          } else {
            let content = {
              content: res.investmentInfos,
              totalSize: res.total
            };
            this.pageResult = content;
            this.pageResult.content.forEach(item => {
              item.nextTrackingDate = /\d{4}-\d{1,2}-\d{1,2}/g.exec(
                item.nextTrackingDate
              );
              if (
                (item.province == null && item.city == null) ||
                (item.province == "null" && item.city == "null")
              ) {
                item.diqu = "";
              } else {
                item.diqu =
                  (CodeToText[item.province] == undefined
                    ? ""
                    : CodeToText[item.province]) +
                  (CodeToText[item.city] == undefined
                    ? ""
                    : CodeToText[item.city]) +
                  (CodeToText[item.area] == undefined
                    ? ""
                    : CodeToText[item.area]) +
                  (item.address == null ? "" : item.address);
              }
              this.student_data_from_options.forEach(type_item => {
                if (type_item.key == item.dataFrom) {
                  item.laiyuan = type_item.value;
                }
              });
              this.student_progress_options.forEach(progress_item => {
                if (progress_item.key == item.progress) {
                  item.getprogress = progress_item.value;
                }
              });
              // 获取方式对应
              this.student_data_from_type_options.forEach(
                data_from_type_item => {
                  if (data_from_type_item.key == item.progress) {
                    item.getType = data_from_type_item.value;
                  }
                }
              );
              // 客户类型对应
              this.student_type_options.forEach(student_type_item => {
                if (student_type_item.key == item.type) {
                  item.type = student_type_item.value;
                }
              });
            });
            this.loading = false;
          }
        })
        .then(data != null ? data.callback : "");
    },
    // 查询学生跟进列表
    findPage2(data) {
      if (data !== null) {
        this.pageRequest2 = data.pageRequest;
      }
      this.$api.agent
        .investmentTrackingById({
          customerId: this.saveData.customerId,
          pageSize: this.pageRequest2.pageSize,
          pageNum: this.pageRequest2.pageNum
        })
        .then(res => {
          let content = {
            content: res.investmentTrackingVos,
            totalSize: res.total
          };
          this.stuqueryTrackingData = content;
          this.stuqueryTrackingData.content.forEach(item => {
            item.nextTrackingDate = /\d{4}-\d{1,2}-\d{1,2}/g.exec(
              item.nextTrackingDate
            );
            this.student_progress_options.forEach(progress_item => {
              if (progress_item.key == item.customerProgress) {
                item.getprogress = progress_item.value;
              }
            });

            this.student_type_options.forEach(type_item => {
              if (type_item.key == item.customerType) {
                item.customerType2 = type_item.value;
              }
            });

            this.student_communication_type.forEach(communication_item => {
              if (communication_item.key == item.contractType) {
                item.contractType = communication_item.value;
              }
            });
          });
        })
        .then(data != null ? data.callback : "");
    },
    // 重置
    reset(queryBox) {
      this.$refs.queryBox.resetFields();
      this.queryBox.customerType = "";
      this.queryBox.customerSource = "";
      this.queryBox.customerProgress = "";
      this.queryBox.providerAgent = "";
      this.createDate = "";
      this.trackingDate = "";
      this.queryBox.dataFromType = "";
      this.queryBox.contactPhone = "";
      this.queryBox.contacts = "";
      this.queryBox.allotType = "";
      this.queryBox.trackingStartDate = "";
      this.queryBox.trackingStopDate = "";
      this.queryBox.createStartDate = "";
      this.queryBox.createStopDate = "";
      this.queryBox.province = "";
      this.queryBox.city = "";
      this.queryBox.area = "";
      this.queryBox.phone = "";
      this.queryBox.assigner = "";
      this.selectedOptions = [];
      this.queryBox.agentName = "";
      this.queryBox.sTodayTracking = "";
      this.pageRequest.pageNum = 1;
      this.nextTrackingDate = "";
      this.queryBox.keyWord = "";
      this.queryBox.nextTrackingStartDate = "";
      this.queryBox.nextTrackingStopDate = "";
      this.queryBox.isRecoveredCustomer = "0";
      this.findPage(null);
    },
    // 批量删除
    handleBatchDelete() {
      this.ids2 = [];
      let idstu2 = this.selections.map(item => item.id);
      // this.dataFormAdd = Object.assign({}, params.row);
      this.ids2 = idstu2;
      let customerIds = this.ids2.join(",");
      this.$confirm(
        "确认删除" + this.selections.length + "个客户吗？",
        "提示",
        {}
      ).then(() => {
        this.editLoading = true;
        this.$api.agent
          .investmentDelete({
            customerIds: customerIds,
            deleteType: 2
          })
          .then(res => {
            this.$message({ message: res.msg, type: "success" });
            this.findPage(null);
          });
      });
    },
    // 查看客户档案
    handleSee: function(params) {
      this.dataForm = Object.assign({}, params.row);
      // console.log(params.row)
      this.$router.push({
        path: "/Customerfile/XuecooAgent",
        query: {
          id: this.dataForm.id,
          customerNumber: params.row.customerNumber
        }
      });
    },
    // 新增客户
    handleNewADD: function() {
      this.$router.push({
        path: "/Customerfile/AddXuecoo",
        query: {
          belongType: "1"
        }
      });
    },
    diquChange: function() {
      let province = this.saveDataDiqu[0];
      let city = this.saveDataDiqu[1];
      let area = this.saveDataDiqu[2];
      this.addTrackingInfo.investmentInfo.province = province;
      this.addTrackingInfo.investmentInfo.city = city;
      this.addTrackingInfo.investmentInfo.area = area;
    },
    closeAddFollow() {
      this.saveDataDiqu = [];
      this.isSpareChange = true;
      this.isSpareChange2 = true;
    },
    // 客户跟进
    handleFollow: function(params) {
      this.saveDataDiqu=[]
      let province = this.saveDataDiqu[0];
      let city = this.saveDataDiqu[1];
      let area = this.saveDataDiqu[2];
      if (params.row.phone1 == null) {
        params.row.phone1 = "";
      }
      if (params.row.phone2 == null) {
        params.row.phone2 = "";
      }
      // 提交修改客户基本信息 只修改phone1 phone2 地区 关键字 客户备注
      let investmentInfo = Object.assign(
        {},
        {
          id: params.row.id,
          province: province,
          city: city,
          area: area,
          contactPhone: params.row.contactPhone,
          phoneAdress: params.row.phoneAdress,
          keyWord: params.row.keyWord,
          customerRemark: params.row.customerRemark,
          phone1: params.row.phone1,
          phone2: params.row.phone2
        }
      );
      this.addTrackingInfo.investmentInfo = investmentInfo;
      if (params.row.phone1 == "") {
        this.isSpareChange = false;
      }
      if (params.row.phone2 == ''&&this.isSpareChange) {
        this.isSpareChange2 = false;
      }
      // 根据回显汉字转code
      if (params.row.customerType != "" && params.row.customerType != null) {
        this.$api.agent
          .queryTypeCode({ key: params.row.customerType })
          .then(res => {
            this.saveData.customerType = res.keyValue.key;
          });
      } else {
        this.saveData.customerType = params.row.customerType;
      }
      if (
        params.row.customerProgress != "" &&
        params.row.customerProgress != null
      ) {
        this.$api.agent
          .queryProgressCode({ key: params.row.customerProgress })
          .then(res => {
            this.saveData.customerProgress = res.keyValue.key;
          });
      } else {
        this.saveData.customerProgress = params.row.customerProgress;
      }
      this.$api.student
        .queryCallAddress({ phone: params.row.contactPhone })
        .then(res => {
           let jsonObj = JSON.parse(res.msg);
          this.addTrackingInfo.investmentInfo.phoneAdress = jsonObj.result.att;
          // let jsonObj = JSON.parse(res.msg).response;
          // let address = [];
          // var arr = [];
          // for (let i in jsonObj) {
          //   arr.push(jsonObj[i]); //属性
          // }
          // if (arr[0]) {
          //   this.addTrackingInfo.investmentInfo.phoneAdress = arr[0].location;
          // } else {
          //   this.addTrackingInfo.investmentInfo.phoneAdress = "未知";
          // }
        });
      this.pageRequest2.pageNum = "1";
      this.addFollow = true;
      this.saveData.id = params.row.id;
      this.saveData.keyWord = params.row.keyWord;
      this.saveData.remark = params.row.remark;
      this.saveData.customerId = params.row.id;
      this.saveData.agentName = params.row.agentName;
      this.saveData.trackingContact = params.row.agentName;
      this.saveData.diqu = params.row.diqu;
      this.saveData.communicationType = "1";
      this.saveData.contactPhone = params.row.contactPhone;
      this.saveData.cityType = params.row.cityType;
      this.investmentInfo = params.row;
      this.saveData.customerRemark = params.row.customerRemark;
      this.saveData.phone1 = params.row.phone1;
      this.saveData.phone2 = params.row.phone2;
      this.addTrackingInfo.investmentInfo.province = params.row.province;
      this.addTrackingInfo.investmentInfo.city = params.row.city;
      this.addTrackingInfo.investmentInfo.area = params.row.area;
      this.saveData.customerSource = params.row.customerSource;
      this.saveData.customerType=params.row.customerType
      if (
        this.addTrackingInfo.investmentInfo.province == null &&
        this.addTrackingInfo.investmentInfo.city == null &&
        this.addTrackingInfo.investmentInfo.area == null
      ) {
        this.saveDataDiqu = [];
      } else if (
        this.addTrackingInfo.investmentInfo.province == "" &&
        this.addTrackingInfo.investmentInfo.city == null &&
        this.addTrackingInfo.investmentInfo.area == null
      ) {
        this.saveDataDiqu.push("");
      } else if (
        this.addTrackingInfo.investmentInfo.province != "" &&
        this.addTrackingInfo.investmentInfo.city == "" &&
        this.addTrackingInfo.investmentInfo.area == null
      ) {
        this.saveDataDiqu.push(
          "" + JSON.stringify(JSON.parse(params.row.province)) + "",
          "" + "" + ""
        );
      } else if (
        this.addTrackingInfo.investmentInfo != "" &&
        this.addTrackingInfo.investmentInfo.city != "" &&
        this.addTrackingInfo.investmentInfo.area == ""
      ) {
        this.saveDataDiqu.push(
          "" + JSON.parse(params.row.province) + "",
          "" + JSON.parse(params.row.city) + "",
          "" + ""
        );
      } else if (
        this.addTrackingInfo.investmentInfo.province != "" &&
        this.addTrackingInfo.investmentInfo.city != "" &&
        this.addTrackingInfo.investmentInfo.area != ""
      ) {
        this.saveDataDiqu.push(
          "" + JSON.parse(params.row.province) + "",
          "" + JSON.parse(params.row.city) + "",
          "" + JSON.parse(params.row.area) + ""
        );
      }
      this.investmentQuery();
      // 获取跟进次数
      this.$api.agent
        .investmentTrackingTrackTimes({
          customerId: this.saveData.customerId
        })
        .then(res => {
          this.saveData.trackingTimes = res.leastTrackTimes;
        });
      this.findPage2(null);
    },
    // 保存跟进数据
    handleSave() {
      let saveDataInfo = Object.assign({}, this.saveData);
      let phone = this.addTrackingInfo.investmentInfo.contactPhone;
      let phone1 = this.addTrackingInfo.investmentInfo.phone1;
      let phone2 = this.addTrackingInfo.investmentInfo.phone2;
      this.addTrackingInfo.trackingInfo=saveDataInfo
      // 判断备用手机号
      if(this.addTrackingInfo.trackingInfo.communicationContent=='undefined'||this.addTrackingInfo.trackingInfo.communicationContent==''){
        this.$message.error("沟通内容不能为空！");
        return 
      }
      if(this.saveData.trackingContact=='undefined'||this.saveData.trackingContact==''){  
        this.$message.error("联系人不能为空！");
        return
      }
      if(!this.isSpareChange&&this.isSpareChange2){
        if(phone1!=''&&phone2==''){
          if(!isMobile(phone1)){
            this.$message.error("请输入正确的备用1手机号！");
            return
          }
          if(phone ==phone1){
            this.$message.error("联系电话与备用电话不能相同！");
            return  
          }
          this.checkRepeatPhone(phone1)
        }
        if(phone1!=''&&phone2!=''){
          if(isMobile(phone1)&&isMobile(phone2)){
            this.submitTrackingInfo()  
          }
        }
        
        if(phone1!=''&&isMobile(phone1)&&phone2==''){
          this.$api.agent.checkPhone({ phone: phone1 }).then(res => {
              if (res.result === 1) {
                this.submitTrackingInfo() 
                // this.isSpareChange2 = false;
              } else {
                this.$message.error("备用电话1" + res.msg);
                return false;
              }
            });
        }   
        if(phone1==''&&this.isSpareChange2) {
          this.submitTrackingInfo() 
        }
      }else if(!this.isSpareChange&&!this.isSpareChange2){
        if(phone2!=''){
          if (phone ==phone2) {
            this.$message.error("联系电话与备用电话不能相同！");
            return 
          }
          if(phone1 ==phone2){
            this.$message.error("备用电话不能相同！");
            return 
          }
          if(!isMobile(phone2)){
            this.$message.error("请输入正确的备用2手机号！");
            return
          }
          // this.submitTrackingInfo()
        }
        if(phone1==''&&phone2==''){
          this.submitTrackingInfo()
        }
        if(phone1!=''&&phone2==''){
          
          if(!isMobile(phone1)){
            this.$message.error("请输入正确的备用1手机号！");
            return
          }
        }
        if(phone1==''&&phone2!=''){
          if(!isMobile(phone1)){
            this.$message.error("请输入正确的备用2手机号！")
            return
          }
        }
        if(phone1!=''&&phone2!=''){
          if(!isMobile(phone2)){
            this.$message.error("请输入正确的备用2手机号！")
            return
          }
          if(!isMobile(phone1)){
            this.$message.error("请输入正确的备用1手机号！")
            return
          }
        }
        if((isMobile(phone1)&&!this.isSpareChange)&&(isMobile(phone2)&&!this.isSpareChange2)){
          this.$api.agent.checkPhone({ phone: phone1 }).then(res => {
            if (res.result == "1") {
              this.isSpareChange2 = false;
            this.$api.agent.checkPhone({ phone: phone2 }).then(res => {
              if (res.result == "1") {
                this.submitTrackingInfo() 
                // this.isSpareChange2 = false;
              } else {
                this.$message.error("备用电话2" + res.msg);
                return false;
              }
            });
          } else {
            this.$message.error("备用电话1" + res.msg);
            return false;
          }
          });  
        }
        if(phone1!=''&&isMobile(phone1)&&phone2==''){
          this.$api.agent.checkPhone({ phone: phone1 }).then(res => {
              if (res.result == "1") {
                this.submitTrackingInfo() 
                // this.isSpareChange2 = false;
              } else {
                this.$message.error("备用电话1" + res.msg);
                return false;
              }
            });
        }      
      }else if((!this.isSpareChange&&!this.isSpareChange2)||(this.isSpareChange&&this.isSpareChange2)){
        this.submitTrackingInfo()
      }else if(this.isSpareChange&&!this.isSpareChange2){
        if(phone1!=''&&phone2!=''){
          if(isMobile(phone1)&&isMobile(phone2)){
            this.submitTrackingInfo()  
          }   
          
        }
        if(phone2==''){
            this.submitTrackingInfo() 
          }
      }
    },
    // 检查手机号是否重复
    checkRepeatPhone(phone) {
      if (phone != "") {
        this.$api.agent.checkPhone({ phone: phone }).then(res => {
          if (res.result == "1") {
            this.isSpareChange2 = false;
          } else {
            this.$message.error("备用电话" + res.msg);
            return false;
          }
        });
      }
    },
    // 提交修改
    submitTrackingInfo() {
      //提交接口 数据结构{investmentInfo:{}客户基本信息,  trackingInfo:{}跟进信息}
      let addTrackingInfo = Object.assign({}, this.saveData);
      this.addTrackingInfo.trackingInfo = addTrackingInfo;
      if(addTrackingInfo.customerType==1||addTrackingInfo.customerType==2||addTrackingInfo.customerType==4){
        if(addTrackingInfo.nextTrackingDate==''){
          this.$message({
              message: "请选择下次跟进日期！",
              type: "error"
            });
            return
        }
      }
      // this.addTrackingInfo.investmentInfo
      this.$api.agent
        .investmentTrackingInfoAdd(this.addTrackingInfo)
        .then(res => {
          if (res.result != 1) {
            this.$message({
              message: res.msg,
              type: "error"
            });
          } else {
            this.$message({
              message: res.msg,
              type: "success"
            });
            this.addFollow = false;
            this.saveData.customerProgress = "";
            this.saveData.customerType = "";
            this.saveData.communicationContent = "";
            this.saveData.nextTrackingDate = "";
            this.saveData.communicationType = "";
            this.saveData.trackingContact = "";
            this.saveData.keyWord = "";
            this.saveData.remark = "";
            this.saveDataDiqu = [];
            this.isSpareChange = true;
            this.isSpareChange2 = true;
            // this.this.addTrackingInfo.trackingInfo.communicationContent
            this.findPage(null);
          }
        });
    },
    // 输入备用电话
    spareChange(value) {
      if (value == "") {
        this.addTrackingInfo.investmentInfo.phone2 = value;
      }
      this.isSpareChange2 = true;
      let isPhone1 = isMobile(this.addTrackingInfo.investmentInfo.phone1);
      if (this.addTrackingInfo.investmentInfo.phone1 == "") {
        return true;
      } else if (!isPhone1) {
        this.$message.error("请输入正确备用1手机号！");
        return false;
      } else if (isPhone1) {
        this.checkRepeatPhone(this.addTrackingInfo.investmentInfo.phone1);
        return true;
      }
    },

    spareChange2() {
      let isPhone2 = isMobile(this.addTrackingInfo.investmentInfo.phone2);
      if (this.addTrackingInfo.investmentInfo.phone2 == "") {
        return true;
      } else if (!isPhone2) {
        this.$message.error("请输入正确备用2手机号！");
        return false;
      } else if (isPhone2) {
        this.checkRepeatPhone(this.addTrackingInfo.investmentInfo.phone2);
        return true;
      }
    },
    // 更新关键字
    updatekeyword() {
      this.$api.agent
        .updatekeyword({
          coustomerId: this.saveData.id,
          keyWord: this.saveData.keyWord
        })
        .then(res => {
          if (res.result === 0) {
            this.$message({
              message: res.msg,
              type: "error"
            });
            return false;
          } else {
            this.findPage(null);
          }
        });
    },
    // 查询签约
    investmentQuery() {
      this.$api.agent
        .investmentQuerySignInfo({
          customerId: this.saveData.id
        })
        .then(res => {
          this.AgentSignInfoData = res.investmentSignInfo;
        });
    },
    // 获取选中的表格数据
    selectionChange: function(selections) {
      this.selections = selections.selections;
    },
    // 修改客户档案
    handleEdit: function(params) {
      this.dataForm = Object.assign({}, params.row);
      // console.log(params.row)
      this.$router.push({
        path: "/Customerfile/EditXuecoo",
        query: {
          id: this.dataForm.id
        }
      });
    },
    // 菜单树选中
    handleOptionClick() {},
    // 获取来源
    get_student_data_from() {
      this.student_data_from_options = JSON.parse(
        localStorage.getItem("investmentSource")
      );
    },
    get_student_progress() {
      this.student_progress_options = JSON.parse(
        localStorage.getItem("investmentProgress")
      );
    },
    student_progress_change(value) {
      this.queryBox.student_progressValue = value.toString();
    },
    get_student_type() {
      this.student_type_options = JSON.parse(
        localStorage.getItem("investmentType")
      );
    },
    get_student_data_from_type() {
      this.student_data_from_type_options = JSON.parse(
        localStorage.getItem("investmentDataFromType")
      );
    },
    student_parent_type_change(value) {
      this.info.studentInfoDetail.studentInfoAttr.parentType = value.toString();
    },
    handleoutbound(params) {
      let studentId = params.row.id;
      this.student = params.row.id;
      this.phone = params.row.contactPhone;
      this.$api.user
        .callOut({
          op: "makecall",
          phone: this.phone,
          uin: Cookies.get("uin"),
          adminUin: Cookies.get("admin_uin"),
          token: Cookies.get("tqToken")
        })
        .then(res => {
          if (res.result == 2) {
            this.$message({
              message: res.msg,
              type: "error"
            });
          } else {
            this.$message({
              message: "外呼成功！",
              type: "success"
            });
          }
        });
      // const makeCallOption = {
      //   phone:params.row.contactPhone,
      //   error: function(ret) {
      //     alert(ret.errmsg)
      //     this.findPage(null)
      //     //操作失败回调函数
      //   },
      //   success: function(ret) {
      //     alert(ret.errmsg)
      //     //操作成功回调函数
      //   }
      // };
      const makeCallCallBack = function(ret, jsonObject) {
        // console.log(JSON.stringify(ret))
      };
      // this.demo.invokeEvent("makecall", makeCallOption, makeCallCallBack);
    },
    wac() {
      // 监听通话事件
      this.demo.monitorEvent(
        "callEvent",
        function(message, jsonObject) {
          console.log("监控通话事件" + this.student);
          // 时间转化
          function timestampToTime(timestamp) {
            let date = new Date(timestamp / 1000);
            var Y = date.getFullYear() + "-";
            var M =
              (date.getMonth() + 1 < 10
                ? "0" + (date.getMonth() + 1)
                : date.getMonth() + 1) + "-";
            var D = date.getDate() + " ";
            var h = date.getHours() + ":";
            var m = date.getMinutes() + ":";
            var s = date.getSeconds();
            return Y + M + D + h + m + s;
          }
          let callDate = timestampToTime(message.call_event.create_time);
          // 通话时长
          let timeLength = (
            (message.call_event.hangup_time - message.call_event.answer_time) /
            1000000
          ).toFixed(0);
          if (timeLength >= 10) {
            this.is_answer = 1;
            timeLength;
          } else {
            this.is_answer = 2;
            timeLength = 0;
          }
          // 提交给服务器
          if (message.call_event.call_state == "agent_hangup") {
            axios
              .post(baseUrl + "/investmentCallInfo/addCallInfo", {
                callDate: callDate, //呼叫时间
                callDuration: timeLength, //通话时长
                tqNumber: Cookies.get("uin"), //通话的TQ号
                connectStatus: this.is_answer, //是否接通 1接通  2未接通
                seatNumber: message.call_event.seat_dbid, //坐席号
                customerId: this.student //呼叫的学生ID
              })
              .then(res => {
                this.findPage(null);
              });
            console.log("挂机");
          }
        }.bind(this)
      );
    },
    // 获取TQtoken
    get_tqToken() {
      const admin_uin = Cookies.get("admin_uin");
      const uin = Cookies.get("uin");
      const strid = "";
      const appid = Cookies.get("appid");
      const appkey = Cookies.get("appkey");
      const ct = Math.round(new Date().getTime() / 1000).toString();
      const sign2 = hex_md5(appid + "*(**)*" + appkey).toUpperCase();
      const ss =
        admin_uin +
        "&" +
        uin +
        "&" +
        strid +
        "&" +
        appid +
        "&" +
        sign2 +
        "&" +
        ct;
      const sign1 = hex_md5(ss).toUpperCase();
      const sign = sign2.toUpperCase();
      axios
        .get("/api/vip/open/auth/token", {
          params: {
            admin_uin: admin_uin,
            uin: uin,
            strid: strid,
            appid: appid,
            ct: ct,
            sign: sign1
          }
        })
        .then(res => {
          // this.tQtoken=res.data.access_token
          console.log(res);
          Cookies.set("TQtoken_init", res.data.access_token);
          // 初始化TQ实例
          this.demo.init({
            debug: true, // 日志是否输出 default false
            strid: "",
            // uin:Cookies.get('TQnumber') , // 账号 / 用户名 必填
            uin: Cookies.get("uin"),
            admin_uin: Cookies.get("admin_uin"), // 管理员账号
            appid: Cookies.get("appid"), // 唯一凭证
            access_token: Cookies.get("TQtoken_init"),
            // access_token:'645EAECEFF9EA9FF237C2FA430B2A1E3A9151E5C3035266D7701E4922AEA5F7F1B77B7762F7774511607EEA61E707FCA' , // 密文
            server_url: "https://vipedu.tq.cn" //如：http://vip.tq.cn
          });
        });
    },
    // 批量导入
    customerManagerImport: function() {
      this.uploadOem = true;
      if (this.form.file != "") {
        this.$refs.uploadExcel.clearFiles();
        this.form.file = "";
      }
    },
    // 文件超出个数限制时的钩子
    exceedFile(files, fileList) {
      this.$notify.warning({
        title: "警告",
        message: `只能选择 ${
          this.limitNum
        } 个文件，当前共选择了 ${files.length + fileList.length} 个`
      });
    },
    // 文件状态改变时的钩子
    fileChange(file, fileList) {
      this.form.file = file.raw;
    },
    // 上传文件之前的钩子, 参数为上传的文件,若返回 false 或者返回 Promise 且被 reject，则停止上传
    beforeUploadFile(file) {
      let extension = file.name.substring(file.name.lastIndexOf(".") + 1);
      let size = file.size / 1024 / 1024;
      if (extension !== "xls") {
        this.$notify.warning({
          title: "警告",
          message: `只能上传Excel97-2004（即后缀是.xls）的文件`
        });
      }
    },
    // 文件上传成功时的钩子
    handleSuccess(res, file, fileList) {
      this.$refs.uploadExcel.clearFiles();
      this.form.file = "";
      this.$notify.success({
        title: "成功",
        message: `文件上传成功,数据处理中,稍后在我的消息中查看！`
      });
    },
    // 文件上传失败时的钩子
    handleError(err, file, fileList) {
      this.$notify.error({
        title: "错误",
        message: `文件上传失败`
      });
    },
    uploadFile() {
      let formData = new FormData();
      formData.append("file", this.form.file);
      axios
        .post(this.uploadUrl, formData, {
          "Content-Type": "multipart/form-data"
        })
        .then(res => {
          if (res.data.result == 1) {
            this.handleSuccess();
            let path = res.data.fileUrl;
            this.$api.agent
              .importStudyKooInfo({ path: path, importFrom: 1 }) //importFrom  1: 我的客户导入; 2: 部门导入（客户分配）; 3:  资源划分导入   4: 客户管理导入
              .then(res => {
                if (res.result == 1) {
                  this.$message({
                    message: res.msg,
                    type: "success"
                  });
                } else {
                  this.$message({
                    message: res.msg,
                    type: "error"
                  });
                }
                this.uploadOem = false;
                this.findPage(null);
              });
          } else {
            this.handleError();
          }
        });
    },

    // 删除上传列表操作
    handleRemove(file, fileList) {
      this.form.file = "";
    },

    // 下载模板
    downloadTmpl() {
      this.getAgentTempl();
    },
    // 沟通形式
    get_contractType() {
      this.$api.user
        .optionsList({ codeType: "investment_communication_type" })
        .then(res => {
          this.student_communication_type = res.keyValueList;
        });
    },
    // 获取时间
    dateFormat: function(time) {
      var date = new Date(time);
      var year = date.getFullYear();
      /* 在日期格式中，月份是从0开始的，因此要加0
       * 使用三元表达式在小于10的前面加0，以达到格式统一  如 09:11:05
       * */
      var month =
        date.getMonth() + 1 < 10
          ? "0" + (date.getMonth() + 1)
          : date.getMonth() + 1;
      var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
      var hours =
        date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
      var minutes =
        date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
      var seconds =
        date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
      // 拼接
      return (
        year +
        "-" +
        month +
        "-" +
        day +
        " " +
        hours +
        ":" +
        minutes +
        ":" +
        seconds
      );
    },
    get_dataTime() {
      let dateTime = new Date();
      this.saveData.trackingDate = this.dateFormat(dateTime);
      let mytime = dateTime.toLocaleTimeString("chinese", { hour12: false }); //获取当前时间
      this.mytime = mytime;
    },
    // 分中心远程搜索
    querySearchAsync(queryString, callback) {
      let restaurants = [{}];
      let results = "";
      this.$api.dropdown.branchcenter().then(res => {
        for (let i of res.branchCenterInfoList) {
          i.value = i.name; //将想要展示的数据作为value
        }
        restaurants = res.branchCenterInfoList;
        results = queryString
          ? restaurants.filter(this.createFilter(queryString))
          : restaurants;
        callback(results);
      });
    },
    createFilter(queryString) {
      return restaurant => {
        return (
          restaurant.name.toLowerCase().indexOf(queryString.toLowerCase()) === 0
        );
      };
    },
    handleSelect(item) {
      this.queryBox.providerAgent = item.id;
    },
    // 销售人员远程搜索
    querySearchAsync2(queryString, callback) {
      let restaurants = [{}];
      let results = "";
      this.$api.dropdown.users({ userType: 3 }).then(res => {
        for (let i of res.userInfoList) {
          i.value = i.realName; //将想要展示的数据作为value
        }
        restaurants = res.userInfoList;
        results = queryString
          ? restaurants.filter(this.createFilter2(queryString))
          : restaurants;
        callback(results);
      });
    },
    createFilter2(queryString) {
      return restaurant => {
        return (
          restaurant.realName
            .toLowerCase()
            .indexOf(queryString.toLowerCase()) === 0
        );
      };
    },
    handleSelect2(item) {
      console.log(item);
      this.queryBox.belongTo = item.id;
    },
    // 获取销售姓名
    get_sale_name() {
      this.$api.dropdown.users({ userType: 3 }).then(res => {
        this.belongTo = res.userInfoList;
      });
    },
    // 点击客户类型
    typeChange() {
      if (this.saveData.customerType == 6) {
        this.saveData.customerProgress = "7";
      }
    },
    // 点击客户进展
    progressChange() {
      if (this.saveData.customerProgress == 7) {
        this.saveData.customerType = "6";
      }
    }
  },
  mounted() {
    this.get_student_data_from();
    this.get_student_progress();
    this.get_student_type();
    this.get_student_data_from_type();
    this.get_tqToken();
    // this.wac();
    this.get_contractType();
    this.get_dataTime();
    this.get_sale_name();
  },
  destroyed: function() {
    this.demo.destroy();
  }
};
</script>
<style>
@import url("../../assets/queryBox.css");
</style>
<style lang="scss" scoped>
.checked-person {
  display: block;
  float: left;
  margin-top: -10%;
  margin-left: 35%;
}
.second-contain-box {
  width: 95%;
  margin: 0 auto;
  .el-col {
    text-align: left;
    margin: 4px 0;
  }
  .el-row {
    margin: 0 0 !important;
  }
  .el-col i {
    font-style: normal;
    display: inline-block;
    margin-top: 10%;
  }
}
.inputbox {
  display: flex;
  flex-direction: row;
  span {
    display: block;
    width: 13%;
  }
  .el-input {
    width: 50%;
  }
  .el-textarea {
    float: left;
    margin-left: -4%;
  }
}
</style>
<style lang="scss">
.batchdistribution-pop {
  .el-dialog__header {
    text-align: left;
    margin-left: 10%;
    font-weight: bold;
  }
}
.chinaeduAddfollow {
  .el-cascader {
    width: 100%;
    margin-top: -8px;
  }
}
</style>
